home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / tools / mg / rexx / global-search.mg < prev    next >
Text File  |  1995-03-09  |  1KB  |  53 lines

  1. /*
  2.  * global-search - if given an argument, goto the top of the first buffer,
  3.  * and start searching for that argument. If not given an argument, then use
  4.  * the default search string, and start searching from where we are.
  5.  * *
  6.  * When a search fails in any buffer, we go to the next buffer and try again.
  7.  * when we run out of buffers, we return with an error.
  8.  */
  9. option failat 2
  10.  
  11. signal on error
  12. 'rexx-buffer-list' buflist
  13. if buflist.0 = 0 then signal error    /* No buflist is an error! */
  14.  
  15. if arg(1, 'Exists') then do        /* start from the top */
  16.     search = arg(1)
  17.     if search = "" then search = '\^M'
  18.     'switch-to-buffer "'buflist.1.name'"'
  19.     'beginning-of-buffer'
  20.     buf = 1
  21.     end
  22. else do                    /* Start where we are now */
  23.     do buf = 1 to buflist.0 while pos("CURRENT", buflist.buf.status) = 0
  24.         nop
  25.         end
  26.     if buf > buflist.0 then signal error    /* No current buffer!?!? */
  27.     search = '\^M'
  28.     end
  29.  
  30. signal off error
  31.  
  32. /* Ready to start searching */
  33. do forever
  34.     'search-forward "'search'"'
  35.     if rc = 0 then exit 0
  36.     buf = buf + 1
  37.     if buf > buflist.0 then signal error
  38.     'switch-to-buffer "'buflist.buf.name'"'
  39.     if rc ~= 0 then signal error
  40.     'beginning-of-buffer'
  41.     if rc ~= 0 then signal error
  42.     end
  43. /*
  44.  * This loop should never exit. However, if it does, the fall through
  45.  * to error will do the righ thing.
  46.  */
  47.  
  48. /*
  49.  * trivial error handler for the setup phase. We do it on the spot in the
  50.  * search phase.
  51.  */
  52. error: exit 1
  53.